package com.hk.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * @Author: zhe
 * @Date: 2021/6/8 11:02
 * @Statement: 统一字符串编码
 */
public class CharacterEncoding {

    public static void setCharacterEncoding(HttpServletRequest request, HttpServletResponse response,String encoding) {
        try {
            request.setCharacterEncoding(encoding);
            response.setCharacterEncoding(encoding);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    public static void setCharacterEncodingResp(HttpServletRequest request, HttpServletResponse response,String encoding) {
        try {
            request.setCharacterEncoding(encoding);
            response.setCharacterEncoding(encoding);
            response.setContentType("application/json;charset=utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

}
